package com.lvs.zmwz.controller.app;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lvs.zmwz.auth.StpUserUtil;
import com.lvs.zmwz.comm.DictionaryEnum;
import com.lvs.zmwz.entity.OrderList;
import com.lvs.zmwz.entity.Shop;
import com.lvs.zmwz.entity.ShopType;
import com.lvs.zmwz.service.IOrderListService;
import com.lvs.zmwz.service.IShopService;
import com.lvs.zmwz.service.IShopTypeService;
import com.lvs.zmwz.util.IdentityUtil;
import com.lvs.zmwz.util.QPage;
import com.lvs.zmwz.util.ResultView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/api/front/shop")
public class AppShopController {

    @Autowired
    private IShopService iShopService;
    @Autowired
    private IOrderListService iOrderListService;

    /**
     * 商品列表
     * @return
     */
    @GetMapping("/list")
    public ResultView list(QPage qPage, Shop sysManagerSearch) {
        IPage<Shop> hjRoleList=this.iShopService.getListAll(qPage,sysManagerSearch);
        return ResultView.ok(hjRoleList);
    }


    /**
     * 商品详情
     * @param shopId
     * @return
     */
    @GetMapping("/getId")
    public ResultView getId(String shopId) {
        return ResultView.ok(this.iShopService.getById(shopId));
    }


    /**
     * 检测当前商品是否已经被购买
     * @param shopId
     * @return
     */
    @GetMapping("/exitBuy")
    public ResultView exitBuy(String shopId) {
        QueryWrapper<OrderList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("status",2);
        queryWrapper.eq("shop_id",shopId);
        queryWrapper.eq("manager_id", StpUserUtil.getLoginIdAsString());
        List<OrderList> orderLists=iOrderListService.list(queryWrapper);
        if(orderLists!=null&&orderLists.size()>=1){
            return ResultView.ok(true);
        }
        return ResultView.ok(false);
    }

}
